USE [genshi]
GO

/****** Object:  Trigger [dbo].[Relics_up]    Script Date: 2022/5/3 20:29:12 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE TRIGGER [dbo].[Relics_up] ON [dbo].[Relics]
AFTER UPDATE
AS
Begin
	SET NOCOUNT ON;
	Declare @pos nvarchar(10);
	Declare @equip nvarchar(10);
	Declare @id smallint
	Declare @mainTagname nvarchar(19);
	Declare @Tagname_1 nvarchar(19);
	Declare @Tagname_2 nvarchar(19);
	Declare @Tagname_3 nvarchar(19);
	Declare @Tagname_4 nvarchar(19);
	Declare @mainTagvalue real;
	Declare @value_1 real;
	Declare @value_2 real;
	Declare @value_3 real;
	Declare @value_4 real;
	Select @pos = position from inserted
	Select @equip = equipped from inserted
	Select @id = id from inserted
	Select @mainTagname = mainTagname from inserted
	Select @Tagname_1 = Tagname_1 from inserted
	Select @Tagname_2 = Tagname_2 from inserted
	Select @Tagname_3 = Tagname_3 from inserted
	Select @Tagname_4 = Tagname_4 from inserted
	Select @mainTagvalue = mainTagvalue from inserted
	Select @value_1 = value_1 from inserted
	Select @value_2 = value_2 from inserted
	Select @value_3 = value_3 from inserted
	Select @value_4 = value_4 from inserted

	if (@pos = 'flower' AND @equip is not null)
		begin
			update Assemble
			set Assemble.Flower = @id
			where Assemble.Name = @equip;
			/*主词条添加*/
			update Assemble
			set Assemble.IncreaseLife = Assemble.IncreaseLife + @mainTagvalue
			where Assemble.Name = @equip;
		end
	else if (@pos = 'feather' AND @equip is not null)
		begin
			update Assemble
			set Assemble.Feather = @id
			where Assemble.Name = @equip;
			/*主词条添加*/
			update Assemble
			set Assemble.IncreaseAttack = Assemble.IncreaseAttack + @mainTagvalue
			where Assemble.Name = @equip;
		end
	else if (@pos = 'sand' AND @equip is not null)
		begin
			update Assemble
			set Assemble.Sand = @id
			where Assemble.Name = @equip;
		end
	else if (@pos = 'cup' AND @equip is not null)
		begin
			update Assemble
			set Assemble.Cup = @id
			where Assemble.Name = @equip;
		end
	else if (@pos = 'head' AND @equip is not null)
		begin
			update Assemble
			set Assemble.Head = @id
			where Assemble.Name = @equip;
		end

	/*主词条添加*/
	if (@equip is not null AND @pos <> 'flower' AND @pos <> 'feather')
		begin
			if (@mainTagname = '攻击力百分比')
				begin
					update Assemble
					set Assemble.AttackPercentage = Assemble.AttackPercentage + @mainTagvalue
					where Assemble.Name = @equip;
				end
			else if(@mainTagname = '生命值百分比')
				begin
					update Assemble
					set Assemble.LifePercentage = Assemble.LifePercentage + @mainTagvalue
					where Assemble.Name = @equip;
				end
			else if(@mainTagname = '防御力百分比')
				begin
					update Assemble
					set Assemble.DefensePercentage = Assemble.DefensePercentage + @mainTagvalue
					where Assemble.Name = @equip;
				end
			else if(@mainTagname = '元素精通')
				begin
					update Assemble
					set Assemble.Mystery = Assemble.Mystery + @mainTagvalue
					where Assemble.Name = @equip;
				end
			else if(@mainTagname = '元素充能效率')
				begin
					update Assemble
					set Assemble.Efficiency = Assemble.Efficiency + @mainTagvalue
					where Assemble.Name = @equip;
				end
			else if(@mainTagname = '火元素伤害加成')
				begin
					update Assemble
					set Assemble.Fire = Assemble.Fire + @mainTagvalue
					where Assemble.Name = @equip;
				end
			else if(@mainTagname = '水元素伤害加成')
				begin
					update Assemble
					set Assemble.Water = Assemble.Water + @mainTagvalue
					where Assemble.Name = @equip;
				end
			else if(@mainTagname = '雷元素伤害加成')
				begin
					update Assemble
					set Assemble.Thunder = Assemble.Thunder + @mainTagvalue
					where Assemble.Name = @equip;
				end
			else if(@mainTagname = '风元素伤害加成')
				begin
					update Assemble
					set Assemble.Wind = Assemble.Wind + @mainTagvalue
					where Assemble.Name = @equip;
				end
			else if(@mainTagname = '冰元素伤害加成')
				begin
					update Assemble
					set Assemble.Ice = Assemble.Ice + @mainTagvalue
					where Assemble.Name = @equip;
				end
			else if(@mainTagname = '岩元素伤害加成')
				begin
					update Assemble
					set Assemble.Rock = Assemble.Rock + @mainTagvalue
					where Assemble.Name = @equip;
				end
			else if(@mainTagname = '物理伤害加成')
				begin
					update Assemble
					set Assemble.Physics = Assemble.Physics + @mainTagvalue
					where Assemble.Name = @equip;
				end
			else if(@mainTagname = '暴击率')
				begin
					update Assemble
					set Assemble.Criticalhit = Assemble.Criticalhit + @mainTagvalue
					where Assemble.Name = @equip;
				end
			else if(@mainTagname = '暴击伤害')
				begin
					update Assemble
					set Assemble.Criticaldamage = Assemble.Criticaldamage + @mainTagvalue
					where Assemble.Name = @equip;
				end
			else if(@mainTagname = '治疗加成')
				begin
					update Assemble
					set Assemble.Treatment = Assemble.Treatment + @mainTagvalue
					where Assemble.Name = @equip;
				end
		end

	/*副词条添加*/
	if (@equip is not null)
	begin
		if(@Tagname_1 = '生命值')
			begin
				update Assemble
				set Assemble.IncreaseLife = Assemble.IncreaseLife + @value_1
				where Assemble.Name = @equip;
			end
		else if(@Tagname_2 = '生命值')
			begin
				update Assemble
				set Assemble.IncreaseLife = Assemble.IncreaseLife + @value_2
				where Assemble.Name = @equip;
			end
		else if(@Tagname_3 = '生命值')
			begin
				update Assemble
				set Assemble.IncreaseLife = Assemble.IncreaseLife + @value_3
				where Assemble.Name = @equip;
			end
		else if(@Tagname_4 = '生命值')
			begin
				update Assemble
				set Assemble.IncreaseLife = Assemble.IncreaseLife + @value_4
				where Assemble.Name = @equip;
			end


		if(@Tagname_1 = '生命值百分比')
			begin
				update Assemble
				set Assemble.LifePercentage = Assemble.LifePercentage + @value_1
				where Assemble.Name = @equip;
			end
		else if(@Tagname_2 = '生命值百分比')
			begin
				update Assemble
				set Assemble.LifePercentage = Assemble.LifePercentage + @value_2
				where Assemble.Name = @equip;
			end
		else if(@Tagname_3 = '生命值百分比')
			begin
				update Assemble
				set Assemble.LifePercentage = Assemble.LifePercentage + @value_3
				where Assemble.Name = @equip;
			end
		else if(@Tagname_4 = '生命值百分比')
			begin
				update Assemble
				set Assemble.LifePercentage = Assemble.LifePercentage + @value_4
				where Assemble.Name = @equip;
			end

		if(@Tagname_1 = '攻击力')
			begin
				update Assemble
				set Assemble.IncreaseAttack = Assemble.IncreaseAttack + @value_1
				where Assemble.Name = @equip;
			end
		else if(@Tagname_2 = '攻击力')
			begin
				update Assemble
				set Assemble.IncreaseAttack = Assemble.IncreaseAttack + @value_2
				where Assemble.Name = @equip;
			end
		else if(@Tagname_3 = '攻击力')
			begin
				update Assemble
				set Assemble.IncreaseAttack = Assemble.IncreaseAttack + @value_3
				where Assemble.Name = @equip;
			end
		else if(@Tagname_4 = '攻击力')
			begin
				update Assemble
				set Assemble.IncreaseAttack = Assemble.IncreaseAttack + @value_4
				where Assemble.Name = @equip;
			end

		if(@Tagname_1 = '攻击力百分比')
			begin
				update Assemble
				set Assemble.AttackPercentage = Assemble.AttackPercentage + @value_1
				where Assemble.Name = @equip;
			end
		else if(@Tagname_2 = '攻击力百分比')
			begin
				update Assemble
				set Assemble.AttackPercentage = Assemble.AttackPercentage + @value_2
				where Assemble.Name = @equip;
			end
		else if(@Tagname_3 = '攻击力百分比')
			begin
				update Assemble
				set Assemble.AttackPercentage = Assemble.AttackPercentage + @value_3
				where Assemble.Name = @equip;
			end
		else if(@Tagname_4 = '攻击力百分比')
			begin
				update Assemble
				set Assemble.AttackPercentage = Assemble.AttackPercentage + @value_4
				where Assemble.Name = @equip;
			end

		if(@Tagname_1 = '防御力')
			begin
				update Assemble
				set Assemble.IncreaseDefense = Assemble.IncreaseDefense + @value_1
				where Assemble.Name = @equip;
			end
		else if(@Tagname_2 = '防御力')
			begin
				update Assemble
				set Assemble.IncreaseDefense = Assemble.IncreaseDefense + @value_2
				where Assemble.Name = @equip;
			end
		else if(@Tagname_3 = '防御力')
			begin
				update Assemble
				set Assemble.IncreaseDefense = Assemble.IncreaseDefense + @value_3
				where Assemble.Name = @equip;
			end
		else if(@Tagname_4 = '防御力')
			begin
				update Assemble
				set Assemble.IncreaseDefense = Assemble.IncreaseDefense + @value_4
				where Assemble.Name = @equip;
			end

		if(@Tagname_1 = '防御力百分比')
			begin
				update Assemble
				set Assemble.DefensePercentage = Assemble.DefensePercentage + @value_1
				where Assemble.Name = @equip;
			end
		else if(@Tagname_2 = '防御力百分比')
			begin
				update Assemble
				set Assemble.DefensePercentage = Assemble.DefensePercentage + @value_2
				where Assemble.Name = @equip;
			end
		else if(@Tagname_3 = '防御力百分比')
			begin
				update Assemble
				set Assemble.DefensePercentage = Assemble.DefensePercentage + @value_3
				where Assemble.Name = @equip;
			end
		else if(@Tagname_4 = '防御力百分比')
			begin
				update Assemble
				set Assemble.DefensePercentage = Assemble.DefensePercentage + @value_4
				where Assemble.Name = @equip;
			end

		if(@Tagname_1 = '元素精通')
			begin
				update Assemble
				set Assemble.Mystery = Assemble.Mystery + @value_1
				where Assemble.Name = @equip;
			end
		else if(@Tagname_2 = '元素精通')
			begin
				update Assemble
				set Assemble.Mystery = Assemble.Mystery + @value_2
				where Assemble.Name = @equip;
			end
		else if(@Tagname_3 = '元素精通')
			begin
				update Assemble
				set Assemble.Mystery = Assemble.Mystery + @value_3
				where Assemble.Name = @equip;
			end
		else if(@Tagname_4 = '元素精通')
			begin
				update Assemble
				set Assemble.Mystery = Assemble.Mystery + @value_4
				where Assemble.Name = @equip;
			end

		if(@Tagname_1 = '元素充能效率')
			begin
				update Assemble
				set Assemble.Efficiency= Assemble.Efficiency + @value_1
				where Assemble.Name = @equip;
			end
		else if(@Tagname_2 = '元素充能效率')
			begin
				update Assemble
				set Assemble.Efficiency = Assemble.Efficiency + @value_2
				where Assemble.Name = @equip;
			end
		else if(@Tagname_3 = '元素充能效率')
			begin
				update Assemble
				set Assemble.Efficiency = Assemble.Efficiency + @value_3
				where Assemble.Name = @equip;
			end
		else if(@Tagname_4 = '元素充能效率')
			begin
				update Assemble
				set Assemble.Efficiency = Assemble.Efficiency + @value_4
				where Assemble.Name = @equip;
			end

		if(@Tagname_1 = '暴击率')
			begin
				update Assemble
				set Assemble.Criticalhit = Assemble.Criticalhit + @value_1
				where Assemble.Name = @equip;
			end
		else if(@Tagname_2 = '暴击率')
			begin
				update Assemble
				set Assemble.Criticalhit = Assemble.Criticalhit + @value_2
				where Assemble.Name = @equip;
			end
		else if(@Tagname_3 = '暴击率')
			begin
				update Assemble
				set Assemble.Criticalhit = Assemble.Criticalhit + @value_3
				where Assemble.Name = @equip;
			end
		else if(@Tagname_4 = '暴击率')
			begin
				update Assemble
				set Assemble.Criticalhit = Assemble.Criticalhit + @value_4
				where Assemble.Name = @equip;
			end

		if(@Tagname_1 = '暴击伤害')
			begin
				update Assemble
				set Assemble.Criticaldamage = Assemble.Criticaldamage + @value_1
				where Assemble.Name = @equip;
			end
		else if(@Tagname_2 = '暴击伤害')
			begin
				update Assemble
				set Assemble.Criticaldamage = Assemble.Criticaldamage + @value_2
				where Assemble.Name = @equip;
			end
		else if(@Tagname_3 = '暴击伤害')
			begin
				update Assemble
				set Assemble.Criticaldamage = Assemble.Criticaldamage + @value_3
				where Assemble.Name = @equip;
			end
		else if(@Tagname_4 = '暴击伤害')
			begin
				update Assemble
				set Assemble.Criticaldamage = Assemble.Criticaldamage + @value_4
				where Assemble.Name = @equip;
			end
	end

End
GO

ALTER TABLE [dbo].[Relics] ENABLE TRIGGER [Relics_up]
GO

